package bit2;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class bitMain23 {
    public static List<String> result=new ArrayList<>();
    public static void getAllFiles(String basePath){
        File file=new File(basePath);
        if (file.isFile()){
            result.add(basePath);
        }else if (file.isDirectory()){
            String[] files= file.list();
            for (String s:files) {
                getAllFiles(basePath+"/"+s);
            }
        }
    }
    public static void main(String[] args) {
        getAllFiles(".");
        for (String s:result) {
            System.out.println(s);
        }
    }
//    public static List<String> result=new ArrayList<>();
//    public static void getAllFiles(String basePath){
//        File file=new File(basePath);
//
//        if (file.isFile()){
//            result.add(basePath);
//            return ;
//        }else if (file.isDirectory()){
//            String[] files= file.list();
//            for (String f:files) {
//                getAllFiles(basePath+"/"+f);
//            }
//        }else {
//            return;
//        }
//    }
    public static void main5(String[] args) {
//        getAllFiles(".");
//        for (String s:result) {
//            System.out.println(s);
//        }
    }
    public static void main4(String[] args) throws IOException {
        File file=new File(".");
        file.createNewFile();
        String[] files= file.list();
        System.out.println(Arrays.toString(files));
    }
    public static void main3(String[] args) throws IOException, InterruptedException {
        File file=new File("helloworld.txt");
        file.createNewFile();
        System.out.println("文件创建成功！");
        Thread.sleep(3000);
        file.deleteOnExit();
        System.out.println("把文件标记成退出删除的状态.  ");
        Thread.sleep(3000);

    }
    public static void main2(String[] args) throws IOException {
        File file=new File("helloworld.txt");
        file.createNewFile();
        System.out.println(file.delete());
//        System.out.println(file.exists());
//        System.out.println(file.isFile());
//        System.out.println(file.isDirectory());
    }
    public static void main1(String[] args) throws IOException {
        File file=new File("./test.txt");
        System.out.println(file.getParent());
        System.out.println(file.getName());
        System.out.println(file.getPath());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getCanonicalPath());
    }
}
